<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>流程节点用户配置</title>
<script src="${ctx}/static/selectWin/userSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script src="${ctx}/static/selectWin/roleSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">
	var $grid;
	$(function() {
		$("#remark").change(function() {
			if ($("#type").combobox('getValue') == 4) {
				$("#fm").form("load", {
					"value" : $("#remark").val(),
					"remark" : $("#remark").val(),
				});
			}
		})
		$("#custom").combobox({
			url : "${ctx}/pub/combobox/wflRelaction",
			onSelect : function(rec) {
				$("#fm").form("load", {
					"value" : rec.value,
					"remark" : rec.text
				});
			}
		});
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/bpm/confUser/dataGrid?search_EQ_bpmConfNode.id=${bpmConfNodeId}",
			fitColumns : true,
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'bpmConfNode',
				title : '所属流程节点',
				formatter : function(value, row, index) {
					return value ? value.name : "";
				}
			}, {
				field : 'remark',
				title : '参与者'
			}, {
				field : 'type',
				title : '类型',
				formatter : function(value, row, index) {
					if (value == 0) {
						return '人员';
					} else if (value == 1) {
						return '常用关系';
					} else if (value == 2) {
						return '角色';
					} else if (value == 3) {
						return '直接领导';
					} else if (value == 4) {
						return 'EL表达式';
					}
				}
			}, {
				field : 'status',
				title : '状态',
				formatter : function(value, row, index) {
					return value == 0 ? "xml文件中读取" : (value == 1 ? "页面配置" : "删除");
				}
			}, {
				field : 'priority',
				title : '权重'
			} ] ]
		}));
		$("#roleSelector").click(function() {
			var type = $("#type").combo("getValue");
			var typeName = $("#type").combo("getText");
			if (type == 2) {
				$.easyui.showGridSelector($.extend(roleSelectOpts, {
					onEnter : function(val) {
						if (val && val.length > 0) {
							$("#fm").form("load", {
								"value" : val[0].roleNo,
								"remark" : typeName + ":" + val[0].roleName
							});
						}
					}
				}));
			} else {
				showAlert("您选择的类型不是角色类型，无法添加角色");
			}
		});
		$("#userSelector").click(function() {
			var type = $("#type").combo("getValue");
			var typeName = $("#type").combo("getText");
			if (type == 0 || type == 1) {
				$.easyui.showGridSelector($.extend(userSelectOpts, {
					onEnter : function(val) {
						var type = $("#type").combobox("getValue");
						if (type == 2) {
							showWarnInfo("选择用户时，类型不能为候选组");
							return false;
						}
						if (val && val.length > 0) {
							$("#fm").form("load", {
								"value" : val[0].id,
								"remark" : "用户:" + val[0].trueName
							});
						}
					}
				}));
			} else {
				showAlert("您选择的类型不是用户类型，无法添加用户");
			}
		});
		$("#add").click(function() {
			$("#fm").form("clear");
			$("#fm").form("load", {
				"bpmConfNode.id" : $("#bpmConfNodeId").val(),
				"type" : 2
			});
			$("#dlg").dialog("open").dialog("setTitle", "新增");
			$("#customSpan").hide();
			$("#normalSpan").show();
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法编辑",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑");
				$("#fm").form("load", $.extend(rowData, {
					"bpmConfNode.id" : $("#bpmConfNodeId").val(),
					"custom" : rowData.value
				}));
				if (rowData.type == 1) {
					$("#normalSpan").hide();
					$("#customSpan").show();
				} else {
					$("#customSpan").hide();
					$("#normalSpan").show();
				}
			}
		});
		$("#delete").click(function() {
			GridDelete("#grid", "${ctx}/bpm/confUser/delete");
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/bpm/confUser/update",
			success : function(data) {
				$grid.datagrid("load");
				showInfoForCallBack(data);
				$("#dlg").dialog('close');
			}
		});
	}

	function typeSelect(rec) {
		$('#remark').attr('readonly', true);
		$('#remark').val('');
		$('#value').val('');
		$("#customSpan").hide();
		$("#normalSpan").show();
		if (rec.value == 0) {
			$('#roleSelector').linkbutton('disable');
			$('#userSelector').linkbutton('enable');
		} else if (rec.value == 1) {
			$('#roleSelector').linkbutton('disable');
			$('#userSelector').linkbutton('disable');
			$("#normalSpan").hide();
			$("#customSpan").show();
			$("#custom").combobox("setValue", "");
		} else if (rec.value == 2) {
			$('#roleSelector').linkbutton('enable');
			$('#userSelector').linkbutton('disable');
		} else if (rec.value == 3) {
			$('#roleSelector').linkbutton('disable');
			$('#userSelector').linkbutton('disable');
			$('#remark').val('直属领导');
			$('#value').val('derectLeader');
			$('#remark').attr('readonly', true);
		} else if (rec.value == 4) {
			$('#roleSelector').linkbutton('disable');
			$('#userSelector').linkbutton('disable');
			$('#remark').attr('readonly', false);
		}
	}
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<input type="hidden" id="bpmConfNodeId" value="${bpmConfNodeId}" /> <a id="add" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-standard-add'">新增</a> <a id="edit" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-pencil'">修改</a> <a id="delete" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-busy'">删除</a>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 400px; height: 250px; padding: 10px 20px"
		data-options="iconCls:'icon-save',resizable:true,modal:true,inline:false, buttons:[
                    { text: '保存', iconCls: 'icon-ok', handler: function () { fn_save(); } },
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg').dialog('close'); } }
                ],closed:true">
		<form id="fm" method="post">
			<input type="hidden" name="id" /> <input type="hidden" name="value" id="value" /> <input type="hidden" name="bpmConfNode.id" />
			<fieldset style="border: solid 1px #aaa; padding: 3px;">
				<legend>编辑</legend>
				<table id="tbl">
					<tr>
						<td>类型:</td>
						<td><select class="easyui-combobox" id="type" name="type" data-options="onSelect:typeSelect" style="width: 150px;">
								<option value="0">人员</option>
								<option value="1">常用关系</option>
								<option value="2">角色</option>
								<option value="3">直属领导</option>
								<option value="4">EL表达式</option>
						</select></td>
					</tr>
					<tr>
						<td>参与者:</td>
						<td><span id="customSpan"> <select class="easyui-combobox" id="custom" name="custom" style="width: 150px;">
							</select>
						</span> <span id="normalSpan"> <input name="remark" id="remark" class="easyui-validatebox" data-opations="required:true" readonly=true>
								<a id="roleSelector" class="easyui-linkbutton easyui-tooltip"
								data-options="plain: true, iconCls: 'icon-cologne-order-1',content:'选取角色',"></a> <a id="userSelector"
								class="easyui-linkbutton easyui-tooltip" data-options="plain: true, iconCls: 'icon-hamburg-special',content:'选取用户'"></a></td>
						</span>
					</tr>
				</table>
			</fieldset>
		</form>
	</div>
</body>
</html>
